import defaultSettings from "@/settings";

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings;

const defaultThemeColor = "#3d6df8";
const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  // 全局主题色
  theme: defaultThemeColor,
};

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    // hasOwnProperty()是一个对象方法  判断对象自身是否拥有某个属性
    if (state.hasOwnProperty(key)) {
      state[key] = value;
    }
  },
  resetTheme: (state) => {
    state.theme = defaultThemeColor;
  },
};

const actions = {
  changeSetting({ commit }, data) {
    commit("CHANGE_SETTING", data);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
